package com.example.lsq.util;



import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class TokenUtil {
    static String tokens="sdaawss";
    public static String grtToken(String userId,String roleName,long time){
       String token= JWT.create()
                .withClaim("userId",userId).withClaim("rolename",roleName).withClaim("time",time)
                .sign(Algorithm.HMAC256("token"));
        return  token;

    }
    public static Map<String,Object> checkToken(String token){
        Map<String,Object> map = new HashMap<>();
        DecodedJWT jwt=JWT.require(Algorithm.HMAC256("token")).build().verify(token);
        Claim userId=jwt.getClaim("userId");
        Claim roleName=jwt.getClaim("roleName");
        Claim time=jwt.getClaim("time");
        map.put("userID",userId.asString());
        map.put("roleName",roleName.asString());
        map.put("time",time.asString());
        return map;


    }



}
